oo::class create PluginFactory {
    variable RenamedPadWidget Language CodePad Objs

    constructor {langObj codePad} {
        set RenamedPadWidget _[set [info object namespace $codePad]::PadWidget]
        set Language $langObj ;#[$language new $RenamedPadWidget]
        set CodePad $codePad
        set Objs {}
    }

    method get {type} {
        set obj [my gen $type]
        lappend Objs $obj
        return $obj
    }

    method gen {type} {
        switch -glob $type {
            doubleQuote {
                return [Quote new $RenamedPadWidget \" $Language]
            }
            singleQuote {
                return [Quote new $RenamedPadWidget \' $Language]
            }
            linum {
                return [Linum new [set [info object namespace $CodePad]::MultiYScroll]]
            }
            folder {
                return [Folder new [set [info object namespace $CodePad]::MultiYScroll] \
                            $Language]
            }
            indent {
                return [Indent new $RenamedPadWidget $Language]
            }
            parenPair* {
                foreach {_ background} $type {}
                return [Pair new $RenamedPadWidget [list \( \)] {parenleft parenright} $background Paren]
            }
            bracketPair* {
                foreach {_ background} $type {}
                return [Pair new $RenamedPadWidget [list \[ \]] {bracketleft bracketright} $background Bracket]
            }
            bracePair* {
                foreach {_ background} $type {}
                return [Pair new $RenamedPadWidget [list \{ \}] {braceleft braceright} $background Brace]
            }
            keyword {
                return [Keyword new $RenamedPadWidget $Language]
            }
            keywordAcc* {
                foreach {_ root num} $type {}
                return [KeywordAcc new $root $num $RenamedPadWidget $Language]
            }
            variable {
                return [Variable new $RenamedPadWidget $Language]
            }
            variableAcc* {
                foreach {_ root num} $type {}
                return [VariableAcc new $root $num $RenamedPadWidget $Language]
            }
            comment {
                return [Comment new $RenamedPadWidget $Language]
            }
            complete {
                return [Complete new $RenamedPadWidget $Language 3 5]
            }
            currentLine* {
                foreach {_ background} $type {}
                return [CurrentLine new $RenamedPadWidget $background]
            }
            microUndo {
                return [MicroUndo new $RenamedPadWidget]
            }
            unicodeFont* {
                foreach {_ font} $type {}
                return [UnicodeFont new $RenamedPadWidget $font]
            }
            notifier* {
                foreach {_f monitor} $type {}
                return [Notifier new $RenamedPadWidget $monitor $Language]
            }
            selection {
                return [Selection new $RenamedPadWidget]
            }
            breakpoint {
                return [BreakPoint new $RenamedPadWidget]
            }
        }
    }

    destructor {
        foreach obj $Objs {
            # puts "destroy $obj \[c\] [info object class $obj]"
            $obj destroy
        }
    }
}